﻿using DevExpress.Data.Filtering;
using DevExpress.Xpo;
using System;
using System.ComponentModel;
using System.Linq;
using 干涉检查Demo;

namespace SqlData
{

    [Persistent(nameof(AbsoluteCalculation))]
    [OptimisticLocking(true), Browsable(true)]
    public class AbsoluteCalculation : XPBaseObject
    {
        public AbsoluteCalculation(Session session) : base(session) { }

        #region  AbsoluteCalculation框架结构
         
        int fID;
        [Key(true)]
        public int ID
        {
            get { return fID; }
            set { SetPropertyValue<int>(nameof(ID), ref fID, value); }
        }


        FileName fFileName;
        [Association(nameof(FileName) + "-" + nameof(AbsoluteCalculation))]
        public FileName FileName
        {
            get { return fFileName; }
            set { SetPropertyValue<FileName>(nameof(FileName), ref fFileName, value); }
        }

        #endregion

        /// <summary>
        /// 绝对计算
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static  bool GetAbsoluteCalculation(string fileName)
        {
            try
            {
                var file = XpoCon.UnitOfShort.Query<AbsoluteCalculation>().FirstOrDefault(u => u.FileName .FullName== fileName);
                if (file != null)
                {
                    return true;
                }
                return false;
            }
            catch (Exception ex)
            {
                XpoCon.UnitOfShort.RollbackTransaction();
                XpoCon.ReleaseShortUnitOfWork();
                Msg.ErrorMessageShow(ex.Message);
                return false;
            }
            finally
            {
                XpoCon.ReleaseShortUnitOfWork();
            }
        }


    }
}

